import {createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
import MyPage from "@/views/myPage/myPage.vue";
import store from "@/store";

const routes = [
  {
    path: '/',
    name: 'home',
    component: () => import('@/views/home/homeWindow.vue'),
    children: [
      {
        path: '/',
        name: 'index',
        meta: {
          title: '首页'
        },
        component: () => import('@/views/index/index.vue')
      },
      {
        path: '/personnel',
        name: 'personnel',
        meta: {
          title: '人员管理'
        },
        component: () => import('@/views/personnel/personnel.vue')
      },
      {
        path: '/addPersonnel',
        name: 'addPersonnel',
        meta: {
          title: '新员工入职'
        },
        component: () => import('@/views/addPersonnel/index.vue')
      },
      {
        path: '/dwgDetail',
        name: 'dwgDetail',
        meta: {
          title: '测试dwg'
        },
        component: () => import('@/views/dwgDetail/index.vue')
      },
        {
        path: '/testDwg',
        name: 'testDwg',
        meta: {
          title: '测试dwg'
        },
        component: () => import('@/views/testDwg/index.vue')
      },
      {
        path: '/editPersonnel',
        name: 'editPersonnel',
        meta: {
          title: '员工详情'
        },
        component: () => import('@/views/editPersonnel/index.vue')
      },
      {
        path: '/organizational',
        name: 'organizational',
        meta: {
          title: '组织架构'
        },
        component: () => import('@/views/organizational/index.vue')
      },
      {
        path: '/role',
        name: 'role',
        meta: {
          title: '角色管理'
        },
        component: () => import('@/views/role/roleList.vue')
      },
      {
        path: '/customForm',
        name: 'customForm',
        meta: {
          title: '编辑自定义模板'
        },
        component: () => import('@/views/customForm/index.vue')
      },
      {
        path: '/permissions',
        name: 'permissions',
        meta: {
          title: '权限列表'
        },
        component: () => import('@/views/permissions/index.vue')
      },
        {
        path: '/ollamaDs',
        name: 'ollamaDs',
        meta: {
          title: 'deepseek'
        },
        component: () => import('@/views/ollamaDs/index.vue')
      },
      {
        path: '/addRole',
        name: 'addRole',
        meta: {
          title: '添加角色'
        },
        component: () => import('@/views/addRole/index.vue')
      },
      {
        path: '/editRole',
        name: 'editRole',
        meta: {
          title: '编辑角色'
        },
        component: () => import('@/views/editRole/index.vue')
      },
    ]
  },
  {
    path: '/login',
    name: 'login',
    meta: {
      title: '登录'
    },
    component: () => import('@/views/login/loginWindow.vue')
  },
  {
    // 👇 非严格匹配，/my-page/* 都指向 MyPage 页面
    path: '/my-page/:page*', // vue-router@4.x path的写法为：'/my-page/:page*'
    name: 'my-page',
    component: MyPage,
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  // history: createWebHashHistory(),
  routes
})
router.beforeEach((to, from) => {
  // ...
  // 返回 false 以取消导航
  document.title = `${to.meta.title} | 通用框架`
  console.log(to)
  store.commit('updateRouterHistory', to)
})
export default router
